using MessagePack;

namespace Crux.Core.Websockets.Redis.Utils;
/// <summary>
/// MessageResolver
/// </summary>
public static class MessagePackUtils
{
    static MessagePackUtils()
    {
        MessagePackSerializer.DefaultOptions = MessagePack.Resolvers.ContractlessStandardResolver.Options;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="valueObject"></param>
    /// <param name="options"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public static byte[] Serialize<T>(
        T valueObject,
        MessagePackSerializerOptions? options = null,
        CancellationToken cancellationToken = default)
    {
        return MessagePackSerializer.Serialize(valueObject, options, cancellationToken);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="buffer"></param>
    /// <param name="options"></param>
    /// <param name="cancellationToken"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public static T Deserialize<T>(
        byte[] buffer,
        MessagePackSerializerOptions? options = null,
        CancellationToken cancellationToken = default)
    {
        return MessagePackSerializer.Deserialize<T>(buffer, options, cancellationToken);
    }
}